<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Admin\Controller;

use Think\Controller;

class AppapplyController extends Controller {

    function index() {
        $User = M('Appapply'); // 实例化User对象
        $keywords = I('get.keys');
        if ($keywords) {
            $map['app_name'] = array('like', '%' . $keywords . '%');
            $map['huiyuan_tel'] = array('eq', $keywords); //多条件
            $map['_logic'] = 'OR';
            $where['_complex'] = $map;
        }
        
        $p = getpage($User, $where, 20);
        foreach ($where as $key => $val) {
           $p->parameter[$key]   =   urlencode($val);
        }
        $list = $User->where($where)->order('ctime desc')->select();
        
        $this->assign('list', $list); // 赋值数据集
        $this->assign('page', $p->show()); // 赋值分页输出
        $this->display();
    }

    /**
     * 导出数据
     */
    public function exportData() {
        $m = M('Appapply');
        $keywords = $_REQUEST['keys'];
        if ($keywords) {
            $map['app_name'] = array('like', '%' . $keywords . '%');
            $map['huiyuan_tel'] = array('eq', $keywords); //多条件
            $map['_logic'] = 'OR';
            $where['_complex'] = $map;
        }
        //$where['Admin.status'] = 2;
        $list = $m->where($where)->order('ctime desc')->select();
        //echo count($list);exit;
        foreach ($list as $key => $value) {
            $list[$key]['xuhao'] = $key + 1;
            $list[$key]['status'] = "已参选";
        }
        $title = array('序号', '名称', '描述', '电话', '报名时间', '状态');
        $field = array('xuhao', 'app_name', 'app_info', 'huiyuan_tel', 'ctime', 'status');
        R('Excel/exportData', array($list, array($title, $field), '报名表格'));
    }

    //审核
    function checkInfo() {
        $id = $_REQUEST['id'];
        $status = $_REQUEST['status'];
        $User = M('Join'); // 实例化User对象
        $card_No = $User->where('id=' . $id)->getField('card_no');
        $state = $User->where('id=' . $id)->save(array('status' => $status, 'ip' => getip(), 'check_time' => $this->crtTime()));
        if ($state) {
            $this->success('数据已保存！', "index");
        } else {
            $this->error('数据未保存！');
        }
    }

}

?>
